package cn.bocweb.spinning.view.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.bocweb.spinning.R;
import cn.bocweb.spinning.model.Bean.GetMyCommentBean;
import cn.bocweb.spinning.view.common.GlideCircle;

/**
 * Created by chenchangxing on 15/12/26.
 */
public class MyCommentAdapter extends RecyclerView.Adapter {

    List<GetMyCommentBean.DataEntity> list;
    Context context;

    public MyCommentAdapter(List<GetMyCommentBean.DataEntity> list) {
        this.list = list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_my_comment, null);
        ViewHolder holder = new ViewHolder(view);
        this.context = parent.getContext();
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewHolder myHolder = (ViewHolder)holder;
        String icon = list.get(position).getUthumb();
            Glide
                    .with(context)
                    .load(icon)
                    .placeholder(R.mipmap.drawer_icon_unlogin)
                    .transform(new GlideCircle(context))
                    .into(myHolder.myCommentIcon);


        if (list.get(position).getImg().get(0) == null || list.get(position).getImg().get(0) == null) {
            myHolder.myCommentInfoImg.setVisibility(View.GONE);
            myHolder.myCommentInfoTitle.setVisibility(View.VISIBLE);
        } else {
            myHolder.myCommentInfoTitle.setVisibility(View.GONE);
            myHolder.myCommentInfoImg.setVisibility(View.VISIBLE);
            Glide
                    .with(context)
                    .load(list.get(position).getImg().get(0))
                    .placeholder(R.mipmap.banner_empty)
                    .into(myHolder.myCommentInfoImg);
        }

        myHolder.myCommentTime.setText(list.get(position).getTime());
        myHolder.myCommentContent.setText(list.get(position).getContent());
        myHolder.myCommentInfoContent.setText(list.get(position).getTitle());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    /**
     * This class contains all butterknife-injected Views & Layouts from layout file 'item_my_comment.xml'
     * for easy to all layout elements.
     *
     * @author ButterKnifeZelezny, plugin for Android Studio by Avast Developers (http://github.com/avast)
     */
    static class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.my_comment_icon)
        ImageView myCommentIcon;
        @Bind(R.id.my_comment_nickname)
        TextView myCommentNickname;
        @Bind(R.id.my_comment_time)
        TextView myCommentTime;
        @Bind(R.id.my_comment_content)
        TextView myCommentContent;
        @Bind(R.id.my_comment_info_title)
        TextView myCommentInfoTitle;
        @Bind(R.id.my_comment_info_img)
        ImageView myCommentInfoImg;
        @Bind(R.id.my_comment_info_content)
        TextView myCommentInfoContent;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
